package com.shf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shf.entity.Product;
import com.shf.mapper.ProductMapper;
import com.shf.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("ps")
@Transactional
public class ProductServicexImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    /**
     * 添加产品
     * @param product
     */
    @Override
    public void addProduct(Product product) {

        int i = productMapper.addProduct(product);
    }


    @Override
    public boolean selectProductByNum(String productNum) {

        String productId = productMapper.selectProductByNum(productNum);

        if (productId != null ){
            return false;
        }
        return true;
    }


    @Override
    public PageInfo<Product> showAllProducts(int page, int size) {
        //开启分页插件
        PageHelper.startPage(page,size);
      List<Product> products = productMapper.showAllProducts();
        PageInfo<Product> pageInfo = new PageInfo<Product>(products);
        return pageInfo;
    }


    @Override
    public Product editById(String id) {


        return productMapper.editById(id);
    }


    @Override
    public void editProduct(Product product) {
        productMapper.editProduct(product);
    }


    @Override
    public void deletePrductById(String id) {
        productMapper.deletePrductById(id);
    }


    @Override
    public void deleteManyByIds(String[] ids) {

        //调用持久层
       int i = productMapper.deleteManyByIds(ids);
    }

    @Override
    public Product showProductDetail(String id) {
      return   productMapper.editById(id);
    }
}
